/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewChannelDialog.java
 *
 * Created on 23 mars 2010, 10:53:36
 */
package chat.client;

import org.jdesktop.application.Action;

/**
 * The application's new channel box for created a channel
 * @author berthise
 */
public class NewChannelDialog extends javax.swing.JDialog {

    /** Creates new form NewChannelDialog
     * @param client 
     * @param modal
     * @param parent
     */
    public NewChannelDialog(ChatView client, java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.client = client;
        initComponents();
        getRootPane().setDefaultButton(okButton);
    }
    private ChatView client = null;

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        infoLabel = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        nameLabel = new javax.swing.JLabel();
        nameTextField = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8));
        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new java.awt.GridLayout(3, 0, 0, 3));

        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        infoLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(NewChannelDialog.class);
        infoLabel.setText(resourceMap.getString("infoLabel.text")); // NOI18N
        infoLabel.setName("infoLabel"); // NOI18N
        jPanel2.add(infoLabel);

        jPanel1.add(jPanel2);

        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setLayout(new java.awt.GridLayout(1, 2, 16, 0));

        nameLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        nameLabel.setText(resourceMap.getString("nameLabel.text")); // NOI18N
        nameLabel.setName("nameLabel"); // NOI18N
        jPanel4.add(nameLabel);

        nameTextField.setText(resourceMap.getString("nameTextField.text")); // NOI18N
        nameTextField.setName("nameTextField"); // NOI18N
        jPanel4.add(nameTextField);

        jPanel1.add(jPanel4);

        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setLayout(new java.awt.GridLayout(1, 2, 16, 0));

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(NewChannelDialog.class, this);
        okButton.setAction(actionMap.get("okChannelBox")); // NOI18N
        okButton.setName("okButton"); // NOI18N
        jPanel3.add(okButton);

        cancelButton.setAction(actionMap.get("closeChannelBox")); // NOI18N
        cancelButton.setName("cancelButton"); // NOI18N
        jPanel3.add(cancelButton);

        jPanel1.add(jPanel3);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     *
     */
    @Action
    public void closeChannelBox() {
        dispose();
    }

    /**
     *
     */
    @Action
    public void okChannelBox() {
        String channelName = new String(nameTextField.getText());
        if (!channelName.isEmpty()) {
            client.newChannel(channelName);
            dispose();
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel infoLabel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables
}
